package io.github.frailty9.crserver.config

import cn.dev33.satoken.stp.StpInterface
import io.github.frailty9.crserver.dso.service.AccountService
import mu.KotlinLogging
import org.noear.solon.annotation.Component
import org.noear.solon.annotation.Inject

@Component
class StpInterfaceImpl: StpInterface {
    private val log = KotlinLogging.logger {  }

    @Inject
    private lateinit var accountService: AccountService

    /**
     * 此系统目前没有权限体系, 所以此方法暂时不用, 直接返回空列表
     */
    @Deprecated("not used")
    override fun getPermissionList(
        loginId: Any,
        loginType: String
    ): List<String> {
        return emptyList()
    }

    override fun getRoleList(
        loginId: Any,
        loginType: String
    ): List<String> {
        val uid = if(loginId is String) loginId.toLong() else loginId as Long
        val roleStr = accountService.getRole(uid)
        val roleListStr = roleStr.split(", ?".toRegex())
        return roleListStr
    }
}